package cn.usian.controller;

import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("findById")
    public User findById(@RequestParam("id") Long id){
       return userService.findById(id);
    }

    @GetMapping("page")
    public Page<User> findPage(@RequestParam(required = true,defaultValue = "1")Integer pageIndex,@RequestParam("name") String name){
        return userService.findPage(pageIndex,name);
    }
    @PostMapping("add")
    public String addUser(@RequestBody User user){
        userService.addUser(user);
        return "添加成功";
    }
    @PostMapping("edit")
    public String edit(@RequestBody User user){
        userService.editUser(user);
        return "添加成功";
    }
    @GetMapping("del")
    public String del(@RequestParam("id") Long id){
        userService.delUser(id);
        return "删除成功";
    }
}
